package b2.widget
{
	import b2.net.*;
	import b2.player.*;
	import b2.scene.*;
	import b2.util.*;
	import b2.widget.login.*;
	import b2.widget.store.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.external.*;

	public class TopBar extends Sprite
	{
		public function TopBar()
		{
			super();
			//背景
			var TopBarBgr:Class = ResourceHelper.getInstance().getClassByName("TopBar");
			var topBarBgr:Sprite = new TopBarBgr();
			topBarBgr.x = BFont.stageWidth - 270;
			topBarBgr.y = 0;
			addChild(topBarBgr);
			//系统
			var SystemIcon:Class = ResourceHelper.getInstance().getClassByName("SystemIcon");
			var systemIcon:BasicIcon = new BasicIcon(SystemIcon, "系统", 1, true);
			systemIcon.x = BFont.stageWidth - systemIcon.width - 10;
			systemIcon.y = 10;
			addChild(systemIcon);
			systemIcon.addEventListener(MouseEvent.CLICK, onSystemIconClick);
			//帮助
			var HelpIcon:Class = ResourceHelper.getInstance().getClassByName("HelpIcon");
			var helpIcon:BasicIcon = new BasicIcon(HelpIcon, "帮助", 1, true);
			helpIcon.x = BFont.stageWidth - helpIcon.width - 65;
			helpIcon.y = 10;
			addChild(helpIcon);
			helpIcon.addEventListener(MouseEvent.CLICK, onHelpIconClick);
			//签到
			var LogonIcon:Class = ResourceHelper.getInstance().getClassByName("LogonIcon");
			var logonIcon:BasicIcon = new BasicIcon(LogonIcon, "签到", 1, true);
			logonIcon.x = BFont.stageWidth - logonIcon.width - 120;
			logonIcon.y = 10;
			addChild(logonIcon);
			logonIcon.addEventListener(MouseEvent.CLICK, onLogonIconClick);
			//商店
			var StoreIcon:Class = ResourceHelper.getInstance().getClassByName("StoreIcon");
			var storeIcon:BasicIcon = new BasicIcon(StoreIcon, "商店", 1, true);
			storeIcon.x = BFont.stageWidth - storeIcon.width - 175;
			storeIcon.y = 10;
			addChild(storeIcon);
			storeIcon.addEventListener(MouseEvent.CLICK, onStoreIconClick);
		}
		
		private function onSystemIconClick(event:MouseEvent):void
		{
			var systemDialog:SystemDialog = SystemDialog.getInstance();
			systemDialog.x = (BFont.stageWidth - systemDialog.width) / 2;
			systemDialog.y = (BFont.stageHeight - systemDialog.height) / 2;
			WidgetManager.getInstance().popOut([systemDialog], true);
		}

		private function onHelpIconClick(event:MouseEvent):void
		{
			ExternalInterface.call("window.open", Profile.URL_HELP_PAGE);
		}

		private function onLogonIconClick(event:MouseEvent):void
		{
			var me:PlayerInfo = PlayerInfoManager.getInstance().players[PlayerInfoManager.getInstance().myUserId];
			var loginDialog:LoginDialog = new LoginDialog(me.logonDayCount);
			WidgetManager.getInstance().popOut([loginDialog], true, true);
		}

		private function onStoreIconClick(event:MouseEvent):void
		{
			var store:Store = Store.getInstance();
			store.refresh(); 
			store.x = (BFont.stageWidth - store.width) / 2;
			store.y = 40;
			WidgetManager.getInstance().popOut([store], true);
		}

	}
}